package com.face.console.dao;

import com.face.console.pojo.dto.RoleMenuDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RoleMenuDtoMapper {
    @Delete({
            "delete from role_menu",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into role_menu (id, role_id, ",
            "menu_id)",
            "values (#{id,jdbcType=BIGINT}, #{roleId,jdbcType=BIGINT}, ",
            "#{menuId,jdbcType=BIGINT})"
    })
    int insert(RoleMenuDto record);

    int insertSelective(RoleMenuDto record);

    @Select({
            "select",
            "id, role_id, menu_id",
            "from role_menu",
            "where id = #{id,jdbcType=BIGINT}"
    })
    RoleMenuDto selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(RoleMenuDto record);

    @Update({
            "update role_menu",
            "set role_id = #{roleId,jdbcType=BIGINT},",
            "menu_id = #{menuId,jdbcType=BIGINT}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(RoleMenuDto record);

    @Select({
            "SELECT em.id, em.role_id roleId, em.menu_id menuId " +
                    "FROM ROLE_MENU em WHERE em.role_id = #{roleId}"
    })
    List<RoleMenuDto> selectAllByRoleId(@Param("roleId") long roleId);

    @Delete({"delete from role_menu where role_id = #{id}"})
    int delByRoleId(@Param("id") Long id);


}